var a = getApp();

Component({
    properties: {
        first: {
            type: Boolean,
            value: !0
        },
        cycleType: {
            type: Number,
            value: 2
        },
        city: {
            type: String,
            value: ""
        },
        province: {
            type: String,
            value: ""
        },
        roleType: {
            type: Number,
            value: 2,
            observer: function(a, t) {
                0 == this.data.first && this.getData(!0);
            }
        },
        clickType: {
            type: Number,
            value: 2,
            observer: function(a, t) {
                0 == this.data.first && this.getData(!0);
            }
        },
        isShow: {
            type: Boolean,
            value: !1,
            observer: function(a, t) {
                1 == this.data.first && 1 == a && this.data.isFirstLoad && this.getData(!0);
            }
        }
    },
    data: {
        dynamics: [],
        pageNo: 1,
        total: -1,
        isFirstLoad: !0,
        toview: "",
        isLoading: !1
    },
    methods: {
        lower: function(a) {
            this.getData(!1);
        },
        getData: function(t) {
            if (!this.data.isLoading) {
                this.setData({
                    isLoading: !0
                }), t && (this.data.pageNo = 1);
                var e, i, o = this, s = this.data.roleType;
                if (4 == this.data.cycleType) {
                    var n = o.data.province, r = o.data.city;
                    if (0 == n.length) return void this.setData({
                        isLoading: !1
                    });
                    "北京市" != n && "上海市" != n && "天津市" != n && "重庆市" != n || (r = ""), e = a.url.searchScheduleRecommendDynamic, 
                    i = {
                        pageNo: o.data.pageNo,
                        pageSize: 20,
                        province: n,
                        role: s,
                        city: r
                    };
                } else e = a.url.hunyuCycleDynamic, s -= s < 4 ? 4 : 3, i = {
                    pageNo: o.data.pageNo,
                    pageSize: 20,
                    cycleType: o.data.cycleType,
                    roleType: s,
                    clickType: o.data.clickType
                };
                a.network.post({
                    url: e,
                    params: i,
                    before: function() {
                        wx.showNavigationBarLoading();
                    },
                    success: function(e) {
                        if (1 == e.data.result) {
                            var i = [];
                            t || (i = o.data.dynamics), i = i.concat(e.data.data.dynamics);
                            var s = o.data.pageNo + 1;
                            o.setData({
                                dynamics: i,
                                pageNo: s,
                                isFirstLoad: !1,
                                first: !1
                            }), t ? o.setData({
                                toview: "top"
                            }) : o.triggerEvent("myevent", {}, {});
                        } else a.util.showToast(e.data.message);
                    },
                    fail: function() {
                        a.util.showToast("获取数据失败");
                    },
                    complete: function() {
                        wx.hideNavigationBarLoading(), wx.stopPullDownRefresh(), o.setData({
                            isLoading: !1
                        });
                    }
                });
            }
        }
    },
    ready: function() {
        this.data.isShow && this.getData(!0);
    }
});